<?php

namespace App\Http\Controllers\Admin\Updatepassword;

use Illuminate\Http\Request;
use App\Http\Controllers\Admin\BaseController;
use DB;
use Crypt;


/**
 * 教师用户修改个人密码
 * Class Updatepassword
 * @package App\Http\Controllers\Admin\Updatepassword
 */
class UpdatepasswordController extends BaseController
{
    protected $service;

    public function __construct()
    {
    	parent::__construct();
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $result['id'] = auth()->user()->id;
        $result['name'] = auth()->user()->name;
        $result['username'] = auth()->user()->username;
        return view('themes.admin.updatepassword.index',compact('result'));
    }

    // 教师用户基本信息修改
    public function editInfo(Request $request) {
        $user_id = auth()->user()->id;
        $name = $request->input('name');
        $username = $request->input('username');
        $password = $request->input('password');
        $password = bcrypt($password);
        $updated_at = date('Y-m-d H:i:s',time());
        $res = DB::table('users')->where('id',$user_id)->update(['name' => $name, 'username' => $username, 'password' => $password, 'updated_at' => $updated_at]);
        if ($res) {
            cacheClear();
            return response()->json(array(
                    'res' => 1
                ));
        }else {
            return response()->json(array(
                    'res' => 0
                ));
        }
    }
}